
package com.xiaoma.myaudience.biz.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.xiaoma.myaudience.R;
import com.xiaoma.myaudience.biz.activity.LoginActivity;
import com.xiaoma.myaudience.biz.activity.ReviewActivity;
import com.xiaoma.myaudience.biz.model.HomeInfoModel;
import com.xiaoma.myaudience.biz.view.LoadingImageView;
import com.xiaoma.myaudience.util.PicUtils;
import com.xiaoma.myaudience.util.model.ModelUtils;

public class PersonalMyAlbumAdapter extends BaseAdapter {

	private Context mContext;
	private List<Map<String, Object>> mList;	
	private LayoutInflater mInflater;
	private String mSizeStr;
	private int mtype;
	public PersonalMyAlbumAdapter(Context context, List<Map<String, Object>> list) {
		mContext = context;
		mList = list;
		mInflater = LayoutInflater.from(context);
		mSizeStr = PicUtils.composeSize(80,100);
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.personal_center_headitem, null);
			ViewHolder holder = new ViewHolder();
			holder.img = (LoadingImageView) convertView.findViewById(R.id.img);
			holder.img.setLoadingIcon(R.drawable.revice_user_head);
            convertView.setTag(holder);

		}
		
		ViewHolder holder = (ViewHolder) convertView.getTag();
		final Map<String, Object> item = (Map<String, Object>) getItem(position);
		holder.img.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext, ReviewActivity.class);
	    		intent.putExtra(HomeInfoModel.PARAM_PICID, 
	    				ModelUtils.getStringValue(item, HomeInfoModel.PARAM_PICID));
	    		intent.putExtra(HomeInfoModel.PARAM_TYPE, "2");
	    		intent.putExtra("from", "LoginActivity");
	    		mContext.startActivity(intent);
			}
		});
		holder.img.setLoadingDrawable(ModelUtils.getStringValue(item, "filepath"), mSizeStr);
		return convertView;
	}

	private class ViewHolder {
        LoadingImageView img;
    }

}
